package com.jl.jlapp.mvp.fragment;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.jl.jlapp.R;
import com.jl.jlapp.adapter.GoodsListAdapter3;
import com.jl.jlapp.adapter.MyFragmentPagerAdapter;
import com.jl.jlapp.eneity.AdvertisementByIdModel;
import com.jl.jlapp.eneity.EffectAdvertisementByTypeModel;
import com.jl.jlapp.eneity.EffectPreSellActivityInformationModel;
import com.jl.jlapp.eneity.GoodsListModel;
import com.jl.jlapp.eneity.MessageNoReadNumModel;
import com.jl.jlapp.eneity.News_ListModel;
import com.jl.jlapp.mvp.activity.ActivityNameActivity;
import com.jl.jlapp.mvp.activity.GoodsDetailActivity;
import com.jl.jlapp.mvp.activity.HomeSearchActivity;
import com.jl.jlapp.mvp.activity.LoginActivity;
import com.jl.jlapp.mvp.activity.MessageCenterActivity;
import com.jl.jlapp.mvp.activity.NoSortGoodsListActivity;
import com.jl.jlapp.mvp.activity.NoSortGoodsListForNewsActivity;
import com.jl.jlapp.mvp.activity.SearchGoodsListActivity;
import com.jl.jlapp.nets.Api;
import com.jl.jlapp.nets.CommonObserver;
import com.jl.jlapp.nets.Net;
import com.jl.jlapp.nets.Transformer;
import com.jl.jlapp.popu.CityPopu;
import com.jl.jlapp.utils.CustomGridLayoutManager;
import com.jl.jlapp.utils.loader.GlideImageLoader;
import com.youth.banner.Banner;
import com.youth.banner.listener.OnBannerListener;
import com.zaaach.citypicker.CityPicker;
import com.zaaach.citypicker.adapter.OnPickListener;
import com.zaaach.citypicker.model.City;
import com.zaaach.citypicker.model.HotCity;

import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

import java.util.ArrayList;
import java.util.List;

public class Fragment_FirstPages
        extends Fragment
        implements OnClickListener {
    public static int flashSaleGoodsId = -1;
    public static List<AdvertisementByIdModel.ResultDataBean.GoodsBean> promotionGoodsList;
    @BindView(R.id.ad_freash)
    ImageView ad_freash;
    @BindView(R.id.ad_hot_sale)
    ImageView ad_hot_sale;
    @BindView(R.id.ad_presale)
    ImageView ad_presale;
    @BindView(R.id.ad_promotion)
    ImageView ad_promotion;
    List<EffectAdvertisementByTypeModel.ResultDataBean> advertisementListByType1;
    List<EffectAdvertisementByTypeModel.ResultDataBean> advertisementListByType3;
    List<EffectAdvertisementByTypeModel.ResultDataBean> advertisementListByType4;
    @BindView(R.id.banner)
    Banner banner;
    @BindView(R.id.banner_limit)
    ImageView banner_limit;
    @BindView(R.id.banner_limit_layout)
    RelativeLayout banner_limit_layout;
    @BindView(R.id.bottom_goods_list_view)
    RecyclerView bottomGoodsListView;
    @BindView(R.id.bottom_more)
    TextView bottom_more;
    private long chaoshitime;
    @BindView(R.id.city)
    TextView city;
    CityPopu cityPopu;
    @BindView(R.id.classify_title1)
    TextView classify_title1;
    @BindView(R.id.classify_title2)
    TextView classify_title2;
    @BindView(R.id.classify_title3)
    TextView classify_title3;
    @BindView(R.id.classify_title4)
    TextView classify_title4;
    @BindView(R.id.classify_title5)
    TextView classify_title5;
    public OnClickListener confirmClick = new OnClickListener() {
        public void onClick(View paramAnonymousView) {
            Fragment_FirstPages.this.cityPopu.dismiss();
            Fragment_FirstPages.this.city.setText("北京");
        }
    };
    private long countdownTime;
    @BindView(R.id.end_time)
    TextView end_time;
    int flashSaleAdId = -1;
    GoodsListAdapter3 goodsListAdapter;
    List<GoodsListModel.ResultDataBean> goodsListModels;
    private List<HotCity> hotCities;
    int hotSaleAdId = -1;
    List<ImageView> imageViews;
    List images;
    @BindView(R.id.img1)
    ImageView img1;
    @BindView(R.id.img2)
    ImageView img2;
    @BindView(R.id.img3)
    ImageView img3;
    ArrayList<ImageView> imgList;
    ArrayList<Fragment> listData;
    @BindView(R.id.location_main)
    LinearLayout location_main;
    @BindView(R.id.icon_message)
    ImageView message;
    String msg = "";
    int newGoodsAdId = -1;
    List<News_ListModel.ResultDataBean> newGoodsList;
    @BindView(R.id.news_more)
    TextView news_more;
    int preSaleAdId = -1;
    List<EffectPreSellActivityInformationModel.ResultDataBean> preSellActivityList;
    List presellImages;
    @BindView(R.id.presell_banner)
    Banner presellbanner;
    int promotionAdId = -1;
    @BindView(R.id.promotion_more)
    TextView promotion_more;
    @BindView(R.id.rl1)
    ImageView rl1;
    @BindView(R.id.rl2)
    ImageView rl2;
    @BindView(R.id.rl3)
    ImageView rl3;
    @BindView(R.id.rl4)
    ImageView rl4;
    @BindView(R.id.rl5)
    ImageView rl5;
    @BindView(R.id.search_main)
    LinearLayout searchMain;
    List<GoodsListModel.ResultDataBean> tempGoodsListModels;
    List<TextView> textViews;
    private String timefromServer;
    int userId = 0;
    //    View view;
    @BindView(R.id.viewpager)
    ViewPager viewpager;

    private void initBanner(List paramList) {
        this.banner.setImageLoader(new GlideImageLoader());
        this.banner.setImages(paramList);
        this.banner.setOnBannerListener(new OnBannerListener() {
            public void OnBannerClick(int paramAnonymousInt) {
                paramAnonymousInt = ((EffectAdvertisementByTypeModel.ResultDataBean) Fragment_FirstPages.this.advertisementListByType1.get(paramAnonymousInt)).getId();
                Net.get().getAdvertisementById(paramAnonymousInt)
                        .compose(Transformer.<AdvertisementByIdModel>switchSchedulers())
                        .subscribe(new CommonObserver<AdvertisementByIdModel>() {
                            @Override
                            protected void onError(String errorMsg) {

                            }

                            @Override
                            protected void onSuccess(AdvertisementByIdModel advertisementByIdModel) {

                            }
                        });

            }
        });
        this.banner.start();
    }

    private void initBottomGoodsList() {
        this.bottomGoodsListView.setLayoutManager(new CustomGridLayoutManager(getActivity(), 2, false));
        this.goodsListAdapter = new GoodsListAdapter3(this.tempGoodsListModels);
        this.bottomGoodsListView.setAdapter(this.goodsListAdapter);
        this.goodsListAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {

            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Intent localIntent = new Intent(Fragment_FirstPages.this.getActivity(), GoodsDetailActivity.class);
                localIntent.putExtra("goodsId", ((GoodsListModel.ResultDataBean) adapter.getItem(position)).getId());
                Fragment_FirstPages.this.startActivity(localIntent);
            }
        });
    }

    private void initPreSellBanner(List paramList) {
        this.presellbanner.setImageLoader(new GlideImageLoader());
        this.presellbanner.setImages(paramList);
        this.presellbanner.setOnBannerListener(new OnBannerListener() {
            public void OnBannerClick(int paramAnonymousInt) {
                paramAnonymousInt = ((EffectPreSellActivityInformationModel.ResultDataBean) Fragment_FirstPages.this.preSellActivityList.get(paramAnonymousInt)).getId();
                Intent localIntent = new Intent(Fragment_FirstPages.this.getActivity(), ActivityNameActivity.class);
                localIntent.putExtra("activityInformationId", paramAnonymousInt);
                Fragment_FirstPages.this.startActivity(localIntent);
            }
        });
        this.presellbanner.start();
    }

    private void initViewPager() {
//        this.viewpager = ((ViewPager) this.view.findViewById(R.id.viewpager));
//        this.img1 = ((ImageView) this.view.findViewById(R.id.img1));
//        this.img2 = ((ImageView) this.view.findViewById(R.id.img2));
//        this.img3 = ((ImageView) this.view.findViewById(R.id.img3));
        int i = promotionGoodsList.size();
        if (i <= 0) {
            return;
        }
        FirstPageHotSaleGoodsListFragment listFragment;
        Bundle bundle;
        listFragment = new FirstPageHotSaleGoodsListFragment();
        bundle = new Bundle();
        bundle.putInt("page", 1);
        listFragment.setArguments(bundle);
        this.listData.add(listFragment);
        this.listData = new ArrayList();
        this.imgList = new ArrayList();
        this.listData.add(listFragment);
        if ((i > 0) && (i <= 3)) {
            this.imgList.add(this.img1);
            this.img2.setVisibility(View.GONE);
            this.img3.setVisibility(View.GONE);
        } else if ((i > 3) && (i <= 6)) {
            this.imgList.add(this.img1);
            this.imgList.add(this.img2);
            this.img3.setVisibility(View.GONE);
            FirstPageHotSaleGoodsListFragment listFragment2 = new FirstPageHotSaleGoodsListFragment();
            Bundle bundle2 = new Bundle();
            bundle2.putInt("page", 2);
            listFragment2.setArguments(bundle2);
            this.listData.add(listFragment2);
        } else if (i > 6) {
            this.imgList = new ArrayList();
            this.imgList.add(this.img1);
            this.imgList.add(this.img2);
            this.imgList.add(this.img3);
            this.listData = new ArrayList();
            FirstPageHotSaleGoodsListFragment listFragment3 = new FirstPageHotSaleGoodsListFragment();
            Bundle localBundle3 = new Bundle();
            localBundle3.putInt("page", 3);
            listFragment3.setArguments(localBundle3);
            this.listData.add(listFragment3);
        }
        if ((this.listData != null) && (this.listData.size() > 0)) {
            MyFragmentPagerAdapter myFragmentPagerAdapter = new MyFragmentPagerAdapter(getChildFragmentManager(), this.listData);
            this.viewpager.setAdapter(myFragmentPagerAdapter);
            this.viewpager.addOnPageChangeListener(new OnPageChangeListener() {
                public void onPageScrollStateChanged(int paramAnonymousInt) {
                }

                public void onPageScrolled(int paramAnonymousInt1, float paramAnonymousFloat, int paramAnonymousInt2) {
                }

                public void onPageSelected(int paramAnonymousInt) {

                    for (int i = 0; i < Fragment_FirstPages.this.imgList.size(); i++) {
                        ((ImageView) Fragment_FirstPages.this.imgList.get(i)).setBackgroundResource(R.drawable.point_gray);
                        if (i == paramAnonymousInt) {
                            ((ImageView) Fragment_FirstPages.this.imgList.get(i)).setBackgroundResource(R.drawable.point_black);
                        }
                    }
                }
            });
        }
    }

    private void setListener() {
        this.searchMain.setOnClickListener(this);
        this.ad_freash.setOnClickListener(this);
        this.message.setOnClickListener(this);
        this.bottom_more.setOnClickListener(this);
        this.news_more.setOnClickListener(this);
        this.promotion_more.setOnClickListener(this);
        this.location_main.setOnClickListener(this);
    }

    public void getAdvertisementGoodsListByType1() {
        Net.get().getEffectAdvertisementByType(1)
                .compose(Transformer.<EffectAdvertisementByTypeModel>switchSchedulers())
                .subscribe(new CommonObserver<EffectAdvertisementByTypeModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(EffectAdvertisementByTypeModel effectAdvertisementByTypeModel) {

                    }
                });

    }

    public void getAdvertisementGoodsListByType3() {
        Net.get().getEffectAdvertisementByType(3)
                .compose(Transformer.<EffectAdvertisementByTypeModel>switchSchedulers())
                .subscribe(new CommonObserver<EffectAdvertisementByTypeModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(EffectAdvertisementByTypeModel effectAdvertisementByTypeModel) {

                    }
                });
    }

    public void getAdvertisementGoodsListByType4() {
        Net.get().getEffectAdvertisementByType(4)
                .compose(Transformer.<EffectAdvertisementByTypeModel>switchSchedulers())
                .subscribe(new CommonObserver<EffectAdvertisementByTypeModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(EffectAdvertisementByTypeModel effectAdvertisementByTypeModel) {

                    }
                });
    }

    public void getAllEffectPreSellActivityInformation() {
        Net.get().getAllEffectPreSellActivityInformation()
                .compose(Transformer.<EffectPreSellActivityInformationModel>switchSchedulers())
                .subscribe(new CommonObserver<EffectPreSellActivityInformationModel>() {

                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(EffectPreSellActivityInformationModel effectPreSellActivityInformationModel) {

                    }
                });
    }

    public void getBottomGoodsListViewData() {
        Net.get().getGoodsList(4, "", "", "true", Double.valueOf(0.0D), Double.valueOf(0.0D), "all", 0)
                .compose(Transformer.<GoodsListModel>switchSchedulers())
                .subscribe(new CommonObserver<GoodsListModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(GoodsListModel goodsListModel) {

                    }
                });
    }

    public void getMessageNum(Integer paramInteger) {
        Net.get().getMessageNum(paramInteger.intValue())
                .compose(Transformer.<MessageNoReadNumModel>switchSchedulers())
                .subscribe(new CommonObserver<MessageNoReadNumModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(MessageNoReadNumModel messageNoReadNumModel) {

                    }
                });

    }

    public void onClick(View paramView) {
        Intent intent;
        switch (paramView.getId()) {
            case R.id.location_main:
                CityPicker.from(getActivity()).enableAnimation(true).setAnimationStyle(R.style.DefaultCityPickerAnimation).setHotCities(null).setOnPickListener(new OnPickListener() {
                    public void onLocate() {
                    }

                    @Override
                    public void onCancel() {

                    }

                    public void onPick(int paramAnonymousInt, City paramAnonymousCity) {
                        TextView localTextView = Fragment_FirstPages.this.city;
                        if (paramAnonymousCity == null) {
                        }
                        for (Object localObject = Fragment_FirstPages.this.city.getText(); ; localObject = paramAnonymousCity.getName()) {
                            localTextView.setText((CharSequence) localObject);
                            if ((paramAnonymousCity != null) && (!"北京".equals(paramAnonymousCity.getName()))) {
                                Fragment_FirstPages.this.cityPopu = new CityPopu(Fragment_FirstPages.this.getContext(), Fragment_FirstPages.this.confirmClick);
                                Fragment_FirstPages.this.cityPopu.setOutsideTouchable(false);
                                Fragment_FirstPages.this.cityPopu.showAtLocation(Fragment_FirstPages.this.getActivity().findViewById(R.id.first_page), 17, 0, 0);
                            }
                            return;
                        }
                    }
                }).show();
                return;
            case R.id.search_main:
                startActivity(new Intent(getActivity(), HomeSearchActivity.class));
                return;
            case R.id.icon_message:
                if (this.userId > 0) {
                    startActivity(new Intent(getContext(), MessageCenterActivity.class));
                    return;
                }
                Toast.makeText(getContext(), "您还未登录，请先登录。", Toast.LENGTH_SHORT).show();
                startActivity(new Intent(getContext(), LoginActivity.class));
                return;
            case R.id.ad_promotion:
                intent = new Intent(getActivity(), NoSortGoodsListActivity.class);
                intent.putExtra("title", "热门促销");
                intent.putExtra("advertisementInformationId", this.promotionAdId);
                startActivity(intent);
                return;
            case R.id.ad_freash:
                if (flashSaleGoodsId <= 0) {
                    Toast.makeText(getActivity(), "暂时还没有限时抢购商品哦，等会儿再来看看吧~", Toast.LENGTH_SHORT).show();
                    return;
                }
                intent = new Intent(getActivity(), GoodsDetailActivity.class);
                intent.putExtra("goodsId", flashSaleGoodsId);
                startActivity(intent);
                return;
            case R.id.ad_hot_sale:
                intent = new Intent(getActivity(), NoSortGoodsListActivity.class);
                intent.putExtra("title", "热卖商品");
                intent.putExtra("advertisementInformationId", this.hotSaleAdId);
                startActivity(intent);
                return;
            case R.id.ad_presale:
                intent = new Intent(getActivity(), NoSortGoodsListActivity.class);
                intent.putExtra("title", "期货预售");
                intent.putExtra("advertisementInformationId", this.preSaleAdId);
                startActivity(intent);
                return;
            case R.id.banner_limit:
                intent = new Intent(getActivity(), GoodsDetailActivity.class);
                intent.putExtra("goodsId", flashSaleGoodsId);
                startActivity(intent);
                return;
            case R.id.bottom_more:
                intent = new Intent(getActivity(), SearchGoodsListActivity.class);
                intent.putExtra("sortType", 4);
                intent.putExtra("classificationId", 0);
                intent.putExtra("searchMsg", "");
                startActivity(intent);
                return;
            case R.id.news_more:
                intent = new Intent(getActivity(), NoSortGoodsListForNewsActivity.class);
                intent.putExtra("title", "新品上架");
                intent.putExtra("classificationId", 0);
                startActivity(intent);
                return;
        }
        intent = new Intent(getActivity(), NoSortGoodsListActivity.class);
        intent.putExtra("title", "火热促销");
        intent.putExtra("advertisementInformationId", this.promotionAdId);
        startActivity(intent);
    }

    public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle) {
        View view = paramLayoutInflater.inflate(R.layout.fragment_main, null, false);
        ButterKnife.bind(this, view);
        this.hotCities = new ArrayList();
        this.hotCities.add(new HotCity("北京", "北京", "101010100"));
        this.hotCities.add(new HotCity("上海", "上海", "101020100"));
        this.hotCities.add(new HotCity("广州", "广东", "101280101"));
        this.hotCities.add(new HotCity("深圳", "广东", "101280601"));
        this.hotCities.add(new HotCity("杭州", "浙江", "101210101"));
        getAdvertisementGoodsListByType4();
        this.textViews = new ArrayList();
        this.imageViews = new ArrayList();
        this.images = new ArrayList();
        this.presellImages = new ArrayList();
        this.imageViews.add(this.rl1);
        this.imageViews.add(this.rl2);
        this.imageViews.add(this.rl3);
        this.imageViews.add(this.rl4);
        this.imageViews.add(this.rl5);
        this.textViews.add(this.classify_title1);
        this.textViews.add(this.classify_title2);
        this.textViews.add(this.classify_title3);
        this.textViews.add(this.classify_title4);
        this.textViews.add(this.classify_title5);
        this.goodsListModels = new ArrayList();
        this.tempGoodsListModels = new ArrayList();
        this.advertisementListByType4 = new ArrayList();
        this.advertisementListByType1 = new ArrayList();
        this.advertisementListByType3 = new ArrayList();
        promotionGoodsList = new ArrayList();
        this.newGoodsList = new ArrayList();
        this.promotionAdId = -1;
        this.newGoodsAdId = -1;
        this.hotSaleAdId = -1;
        this.preSaleAdId = -1;
        this.flashSaleAdId = -1;
        flashSaleGoodsId = -1;
        this.userId = getActivity().getSharedPreferences("JLAppData", 0).getInt("userId", -1);
        if (this.userId > 0) {
            getMessageNum(Integer.valueOf(this.userId));
        }
        setListener();
        getAdvertisementGoodsListByType1();
        getAllEffectPreSellActivityInformation();
        getBottomGoodsListViewData();
        getAdvertisementGoodsListByType3();
        this.message.setImageResource(R.drawable.icon_message_white);
        return view;

    }

//
//    @Override
//    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
//        super.onViewCreated(view, savedInstanceState);
//
//        initBanner(images);
//
//        initViewPager();
//        initBottomGoodsList();
//        initPreSellBanner(presellImages);
//    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/mvp/fragment/Fragment_FirstPages.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */